﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using DocumentManagement.Views;

namespace DocumentManagement.ViewsModels
{
    public class PageSwitcherEventArgs : EventArgs
    {
        public bool Result { get; set; }
    }

    public static class PageSwitcher
    {
        public static HomeWindow homeWindow;

        public static EventHandler<PageSwitcherEventArgs> PageChanging;
        public static EventHandler<PageSwitcherEventArgs> PageChanged;

        public static void Switch(UserControl newPage)
        {
            var eventArgs = new PageSwitcherEventArgs { Result = true };

            if (PageChanging != null)
                PageChanging.Invoke(homeWindow.Content.Children[0], eventArgs);

            if (!eventArgs.Result)
                return;

            homeWindow.Content.Children.Clear();
            homeWindow.Content.Children.Add(newPage);

            if (PageChanged != null)
                PageChanged.Invoke(homeWindow, null);
        }
    }
}
